<template>
    <div class="addDevice">
        <div class="addBox">
            <div class="cm">
                <label for="name"><img src="../../assets/images/icon-name.png" alt=""></label>
                <input id="name" type="text" v-model="name" placeholder="请输入设备名称">
            </div>
            <div class="cm">
                <label for="number"><img src="../../assets/images/icon-number.png" alt=""></label>
                <input id="number" type="text" v-model="number" placeholder="请输入设备序列号">
            </div>
        </div>
        <div class="addDeviceBtn" @click="goList">添加设备</div>
    </div>
</template>
<script>
    import { MessageBox } from 'mint-ui'
    import { addDevice as addDeviceUrl } from '../../code/api'
    export default {
        data() {
            return {
                home: 'addDevice',
                name: '',
                number: ''
            }
        },
        created() {
            console.log(sessionStorage.getItem('user_token'))
        },
        methods: {
            goList() {
                let option = {
                    user_token: sessionStorage.getItem('user_token'),
                    flowmeter_serial_number: this.number,
                    flowmeter_nickname: this.name
                }
                if (this.name != '' && this.number != '') {
                    this.$http.post(addDeviceUrl, option).then((res) => {
                        console.log(res)
                        MessageBox.alert(res.body).then(action => {
                            this.$router.push('lists')
                        })
                    },error => {
                        MessageBox.alert(error.body.message);
                    })
                } else {
                    MessageBox.alert('请填写完整信息');
                }
            }
        },
        components: {
            'MessageBox': MessageBox
        }
    }

</script>
<style>
    .addDevice {
        padding-top: 20px;
        box-sizing: border-box;
    }

    .addDevice .addBox {
        background: #fff;
    }

    .addBox .cm {
        padding: 10px 0;
        position: relative;
        box-sizing: border-box;
    }

    .addBox .cm:first-child {
        border-bottom: 1px solid #cdcdcd;
    }

    .addBox .cm img {
        position: absolute;
    }

    .addBox .cm:first-child img {
        width: 32px;
        height: 29px;
        left: 30px;
        top: 34%;
    }

    .addBox .cm:nth-of-type(2) img {
        width: 32px;
        height: 24px;
        left: 30px;
        top: 35%;
    }

    .addBox input {
        border: none;
        padding: 20px;
        padding-left: 90px;
        box-sizing: border-box;
    }

    .addDeviceBtn {
        padding: 20px 0;
        background: #afceaa;
        width: 90%;
        margin: 50px auto;
        text-align: center;
        color: #fff;
        border-radius: 10px;
    }

    .addDeviceBtn:hover {
        background: #fcebab;
    }

     ::-webkit-input-placeholder {
        color: #cdcdcd;
    }

     :-ms-input-placeholder {
        color: #cdcdcd;
    }

     ::-moz-placeholder {
        color: #cdcdcd;
    }
</style>